package com.principle.ocp;

/**
 * @author 冯志立
 * @create 2019-10-15 16:22
 */
public class Ocp {
    public static void main(String[] args) {

    }
}

//用于绘图的类[使用方]
class GraphicEditor {

    //接受shape对象，根据type绘制图形
    public void drawShape(Shape s) {
        if (s.m_type == 1) {
            drawRectangle(s);
        } else if (s.m_type == 2) {
            drawCircle(s);
        } else if (s.m_type == 3){
            drawTriangle(s);
        }
    }

    public void drawRectangle(Shape r) {
        System.out.println("绘制矩形");
    }

    public void drawCircle(Shape r) {
        System.out.println("绘制圆形");
    }
    public void drawTriangle(Shape r) {
        System.out.println("绘制三角形");
    }

}

//基类
class Shape {
    int m_type;
}

class Rectangle extends Shape {
    Rectangle() {
        super.m_type = 1;
    }
}

class Circle extends Shape {
    Circle(){
        super.m_type = 2;
    }
}

class Triangle extends Shape {
    Triangle(){
        super.m_type = 3;
    }
}